package PokerGame;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String[] suits = {"♥", "♣", "♦", "♠"};

    public List<Poker> buyPoker() {
        List<Poker> pokers = new ArrayList<>();
        //每一张Poker都需要有四种颜色
        for (int i = 0; i < 4; i++) {
            //每一种颜色都需要生成13张牌
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(suits[i],j);
                pokers.add(poker);
            }
        }
        return pokers;
    }
    public void shuffle(List<Poker> pokers) {
        for (int i = pokers.size() - 1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i);//这里就是生成一个0-51的随机数
            //交换: 生成一个随机数，从最后一张牌开始和前边的牌交换
            swap(pokers,i,index);
        }
    }

    private void swap(List<Poker> pokers,int i, int j) {
        Poker tmp = pokers.get(i);
        pokers.set(i,pokers.get(j));//这里调用的是List的set方法
        pokers.set(j,tmp);
    }

    public List<List<Poker>> game(List<Poker> pokers) {
        List<List<Poker>> hand = new ArrayList<>();
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //最外层循环 控制轮数
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Poker removePoker = pokers.remove(0);
                hand.get(j).add(removePoker);
            }
        }
        return hand;
    }
}
